<template>
  <div class="manage">
    <!-- 1.顶部区域 -->
    <div class="header">
      <div class="left">用户id: <input type="text" ref="sousuo1" /></div>
      <div class="left">用户名: <input type="text" ref="sousuo2" /></div>
      <div class="right">
        <el-button type="primary" size="small" @click="requireManage()"
          >查询</el-button
        >
      </div>
    </div>
    <!-- 2.table信息 -->
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="logId" label="id" width="80" align="center">
      </el-table-column>
      <el-table-column prop="logUsername" label="用户名" align="center">
      </el-table-column>
      <el-table-column prop="logName" label="真实姓名" align="center">
      </el-table-column>
      <el-table-column prop="logDesc" label="动态" align="center">
      </el-table-column>

      <el-table-column prop="logCreatetime" label="日创建时间" align="center">
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <div class="block">
      <span class="demonstration"></span>
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-change="currentPage1"
        :page-sizes="[2, 4, 6, 8]"
        :page-size="limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { showStudentLog, inquireStudentLog } from "@/apis/zhuomeng/Index.js";
export default {
  data() {
    return {
      dialogVisible: false,
      tableData: [],
      total: 0,
      page: 1,
      limit: 3,
      currentPage1: 1,
    };
  },
  methods: {
    // 1.获取学生日志数据
    showall() {
      showStudentLog(this.page, this.limit).then((ok) => {
        console.log(ok);
        this.tableData = ok.data.data.records;
        this.total = ok.data.data.records ? ok.data.data.records.length : 0;
      });
    },
    showany() {
      showStudentLog(this.page, this.limit).then((ok) => {
        console.log(ok);
        this.tableData = ok.data.data.records;
      });
    },

    // 2.id，用户名查询请求
    requireManage() {
      if (this.$refs.sousuo1.value != 0 && this.$refs.sousuo2.value != 0) {
        inquireStudentLog(
          this.$refs.sousuo1.value,
          this.$refs.sousuo2.value
        ).then((ok) => {
          console.log(ok);
          this.tableData = ok.data.data.records;
          this.limit = this.tableData.length;
          this.showall();
        });
      }
    },
    // 3.分页器
    handleSizeChange(val) {
      this.limit = val;
      // console.log(this.limit);
      this.showany();
    },
    handleCurrentChange(val) {
      this.page = val;
      // console.log(this.page);
      this.showany();
    },
  },
  mounted() {
    //调用获取数据列表
    this.showall();
  },
};
</script>

<style scoped>
#app {
  background: white;
}
.header {
  display: flex;
}
.header input {
  height: 30px;
  border: 1px solid #ccc;
  margin-left: 20px;
}
.header .left {
  margin-right: 30px;
}
.el-table {
  margin-top: 20px;
}
.block {
  margin-top: 30px;
}
</style>
